/**
 * Created by Ysssssss on 2021/4/12.
 */
import { put, takeEvery } from 'redux-saga/effects'
import apiType, {
    GET_PRODUCT_LIST,
    GET_PRODUCT_TYPE_LIST,
    GET_PRODUCT_TYPE_SELECTION,
    GET_PRODUCT_PROPERTY_LIST,
    GET_PRODUCT_SELECTION,
    GET_PRODUCT_DETAIL_INFO,
    CREATE_PRODUCT_TYPE,
    EDIT_PRODUCT_TYPE,
    DELETE_PRODUCT_TYPE,
    EDIT_PRODUCT_PROPERTY,
    DELETE_PRODUCT_PROPERTY,
    CREATE_PRODUCT_PROPERTY,
    CREATE_PRODUCT,
    EDIT_PRODUCT,
    DELETE_PRODUCT,
    GET_PRODUCT_IMPORT_TASK_LIST,
    GET_PRODUCT_IMPORT_TASK_PROGRESS,
    PRODUCT_IMPORT,
    GET_SUPPLY_GROUP_LIST,
    CREATE_SUPPLY_GROUP,
    EDIT_SUPPLY_GROUP,
    DELETE_SUPPLY_GROUP,
    GET_SUPPLY_GROUP_DETAIL_INFO,
    COPY_SUPPLY_GROUP,
    SET_SUPPLY_GROUP_RELATED_STORES,
    GET_SUPPLY_GROUP_PRODUCT_LIST,
    BULK_ADD_PRODUCT_TO_SUPPLY_GROUP,
    BULK_DELETE_PRODUCT_FROM_SUPPLY_GROUP, EDIT_SUPPLY_GROUP_PRODUCT_PRICE,
    GET_PRODUCT_NATURE_STATS
} from "@constants/ActionTypes";
import {deleteAxios, getAxios, postAxios, putAxios} from "@utils/api";

/**
 * 查看商品类型概况
 * @returns {{type: string}}
 */
export const getProductNatureStats = () => ({
    type: apiType(GET_PRODUCT_NATURE_STATS).request,
})

/**
 * 获取商品列表
 * @param productNature
 * @param query
 * @param productType
 * @param pageNo
 * @param pageSize
 * @param callback
 * @returns {{callback: *, type: string, params: {pageNo: *, query: *, pageSize: *}}}
 */
export const getProductList = ({ productNature, query, productType, pageNo, pageSize }, callback) => {
    const params = {
        query,
        pageNo,
        pageSize,
        nature: productNature
    }
    if (productType) {
        params.prodTypeId = productType
    }
    return {
        type: apiType(GET_PRODUCT_LIST).request,
        params,
        callback
    }
}

/**
 * 创建商品
 * @param params
 * @param callback
 * @returns {{callback: *, type: string, params: *}}
 */
export const createProduct = ({ productNature, skus, ...params}, callback) => ({
    type: apiType(CREATE_PRODUCT).request,
    params: {
        nature: productNature,
        skuList: skus,
        ...params
    },
    callback
})

/**
 * 编辑商品
 * @param params
 * @param callback
 * @returns {{callback: *, type: string, params: *}}
 */
export const editProduct = ({skus, ...params}, callback) => ({
    type: apiType(EDIT_PRODUCT).request,
    params: {
        skuList: skus,
        ...params
    },
    callback
})

/**
 * 批量删除商品
 * @param ids
 * @param id
 * @param callback
 * @returns {{callback: *, type: string, params: {ids: *}}}
 */
export const bulkDeleteProduct = ({ ids, id }, callback) => ({
    type: apiType(DELETE_PRODUCT).request,
    params: {
        ids: id ? [ id ] : ids
    },
    callback
})

/**
 * 获取商品selection
 * @param pageNo
 * @param pageSize
 * @param prodTypeId
 * @param query
 * @returns {{type: string, params: {pageNo: *, query: *, pageSize: *, prodTypeId: *}}}
 */
export const getProductSelection = ({ pageNo, pageSize, prodTypeId, excludedMenuId, query }) => {
    const params = {
        query,
        pageNo,
        pageSize,
        prodTypeId,
        excludedMenuId
    }
    return {
        type: apiType(GET_PRODUCT_SELECTION).request,
        params
    }
}

/**
 * 获取商品详情
 * @param id
 * @param callback
 * @returns {{callback: *, type: string, params: {id: *}}}
 */
export const getProductDetailInfo = ({ id }, callback) => ({
    type: apiType(GET_PRODUCT_DETAIL_INFO).request,
    params: {id},
    callback
})

/**
 * 获取商品分类列表
 * @param productNature
 * @returns {{type: string, params: {nature: number}}}
 */
export const getProductTypeList = ({productNature} = {}) => ({
    type: apiType(GET_PRODUCT_TYPE_LIST).request,
    params: {
        nature: productNature || 0
    },
})

/**
 * 获取商品分类selection
 * @param productNature
 * @param callback
 * @returns {{callback: *, type: string, params: {nature: number}}}
 */
export const getProductTypeSelection = ({productNature = 0, pStoreId} = {}, callback) => ({
    type: apiType(GET_PRODUCT_TYPE_SELECTION).request,
    params: {
        nature: productNature,
        pStoreId,
    },
    callback
})

/**
 * 创建商品分类
 * @param name
 * @param productNature
 * @param parentId
 * @param callback
 * @returns {{callback: *, type: string, params: {nature: *, name: *, parentId: *}}}
 */
export const createProductType = ({name, productNature, parentId}, callback) => ({
    type: apiType(CREATE_PRODUCT_TYPE).request,
    params: {
        name,
        nature: productNature,
        parentId
    },
    callback
})

/**
 * 编辑商品分类
 * @param id
 * @param name
 * @param parentId
 * @param callback
 * @returns {{callback: *, type: string, params: {name: *, id: *, parentId: *}}}
 */
export const editProductType = ({id, name, parentId}, callback) => ({
    type: apiType(EDIT_PRODUCT_TYPE).request,
    params: {
        id,
        name,
        parentId
    },
    callback
})

/**
 * 删除商品分类
 * @param id
 * @param callback
 * @returns {{callback: *, type: string, params: {id: *}}}
 */
export const deleteProductType = ({id}, callback) => ({
    type: apiType(DELETE_PRODUCT_TYPE).request,
    params: {
        id
    },
    callback
})

/**
 * 获取商品属性组列表
 * @returns {{type: string}}
 */
export const getProductPropertyList = ({ productNature }) => ({
    type: apiType(GET_PRODUCT_PROPERTY_LIST).request,
    params: {
        nature: productNature
    }
})

/**
 * 创建商品属性组
 * @param name
 * @param items
 * @param productNature
 * @param callback
 * @returns {{callback: *, type: string, params: {nature: *, name: *, items: *}}}
 */
export const createProductProperty = ({ name, items, productNature }, callback) => ({
    type: apiType(CREATE_PRODUCT_PROPERTY).request,
    params: {
        name,
        items,
        nature: productNature
    },
    callback
})

/**
 * 编辑商品属性组
 * @param name
 * @param items
 * @param callback
 * @returns {{callback: *, type: string, params: {name: *, items: *}}}
 */
export const editProductProperty = ({ name, items }, callback) => ({
    type: apiType(EDIT_PRODUCT_PROPERTY).request,
    params: {
        name,
        items,
    },
    callback
})

/**
 * 删除商品属性组
 * @param name
 * @param callback
 * @returns {{callback: *, type: string, params: {name: *}}}
 */
export const deleteProductProperty = ({ name }, callback) => ({
    type: apiType(DELETE_PRODUCT_PROPERTY).request,
    params: {
        name,
    },
    callback
})

/**
 * 获取商品导入列表 todo 暂时先支持展示前20条
 * @param productNature
 * @returns {{type: string, params: {nature: *, pageNo: number, pageSize: number}}}
 */
export const getProductImportTaskList = ({ productNature }) => ({
    type: apiType(GET_PRODUCT_IMPORT_TASK_LIST).request,
    params: {
        nature: productNature,
        pageSize: 1,
        pageNo: 20
    },
})

/**
 * 获取上传任务进度
 * @param id
 * @param callback
 * @returns {{callback: *, type: string, params: {id: *}}}
 */
export const getProductImportTaskProgress = ({id}, callback) => ({
    type: apiType(GET_PRODUCT_IMPORT_TASK_PROGRESS).request,
    params: {
        id
    },
    callback
})

/**
 * 商品上传
 * @param productNature
 * @param link
 * @param updateMode
 * @param callback
 * @returns {{callback: *, type: string, params: {nature: *, updateMode: *, link: *}}}
 */
export const productImport = ({ productNature, link, updateMode }, callback) => ({
    type: apiType(PRODUCT_IMPORT).request,
    params: {
        nature: productNature,
        link,
        updateMode
    },
    callback
})

/**
 * 获取供货组列表
 * @returns {{type: {request: string, success: string, failure: string}}}
 */
export const getSupplyGroupList = () => ({
    type: apiType(GET_SUPPLY_GROUP_LIST).request
})

/**
 * 获取供货组详情
 * @param id
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {id: *}}}
 */
export const getSupplyGroupDetailInfo = ({ id }, callback) => ({
    type: apiType(GET_SUPPLY_GROUP_DETAIL_INFO).request,
    params: {
        id
    },
    callback
})

/**
 * 创建供货组
 * @param name
 * @param pic
 * @param canModifyPrice
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {canModifyPrice: *, name: *, pic: *}}}
 */
export const createSupplyGroup = ({name, pic, canModifyPrice}, callback) => ({
    type: apiType(CREATE_SUPPLY_GROUP).request,
    params: {
        name,
        pic,
        canModifyPrice
    },
    callback
})

/**
 * 编辑供货组
 * @param id
 * @param name
 * @param pic
 * @param canModifyPrice
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {canModifyPrice: *, name: *, id: *, pic: *}}}
 */
export const editSupplyGroup = ({id, name, pic, canModifyPrice}, callback) => ({
    type: apiType(EDIT_SUPPLY_GROUP).request,
    params: {
        id,
        name,
        pic,
        canModifyPrice
    },
    callback
})

/**
 * 删除供货组
 * @param id
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {id: *}}}
 */
export const deleteSupplyGroup = ({ id }, callback) => ({
    type: apiType(DELETE_SUPPLY_GROUP).request,
    params: {
        id,
    },
    callback
})

/**
 * 复制供货组
 * @param id
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {id: *}}}
 */
export const copySupplyGroup = ({ id }, callback) => ({
    type: apiType(COPY_SUPPLY_GROUP).request,
    params: {
        id,
    },
    callback
})

/**
 * 设置供货组关联店铺
 * @param id
 * @param storeIds
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {id: *, storeIds: *}}}
 */
export const setSupplyGroupRelatedStores = ({ id, storeIds }, callback) => ({
    type: apiType(SET_SUPPLY_GROUP_RELATED_STORES).request,
    params: {
        id,
        storeIds
    },
    callback
})

/**
 * 获取供货组内商品列表
 * @param menuId
 * @param pageNo
 * @param pageSize
 * @param prodTypeId
 * @param query
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {pageNo: *, query: *, menuId: *, pageSize: *, prodTypeId: *}}}
 */
export const getSupplyGroupProductList = ({menuId, pageNo, pageSize, prodTypeId, query}, callback) => ({
    type: apiType(GET_SUPPLY_GROUP_PRODUCT_LIST).request,
    params: {
        menuId,
        pageNo,
        pageSize,
        prodTypeId,
        query,
    },
    callback
})

/**
 * 批量添加商品至供货组
 * @param menuId
 * @param prodIds
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {menuId: *, prodIds: *}}}
 */
export const bulkAddProductToSupplyGroup = ({ menuId, prodIds }, callback) => ({
    type: apiType(BULK_ADD_PRODUCT_TO_SUPPLY_GROUP).request,
    params: {
        menuId,
        prodIds
    },
    callback
})

/**
 * 批量删除供货组内商品
 * @param menuId
 * @param prodIds
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {menuId: *, prodIds: *}}}
 */
export const bulkDeleteProductFromSupplyGroup = ({ menuId, prodIds }, callback) => ({
    type: apiType(BULK_DELETE_PRODUCT_FROM_SUPPLY_GROUP).request,
    params: {
        menuId,
        prodIds
    },
    callback
})

/**
 * 修改供货组内商品价格
 * @param menuId
 * @param prodId
 * @param skus
 * @param callback
 * @returns {{callback: *, type: {request: string, success: string, failure: string}, params: {skus: *, menuId: *, prodId: *}}}
 */
export const editSupplyGroupInfoPrice = ({ menuId, prodId, skus}, callback) => ({
    type: apiType(EDIT_SUPPLY_GROUP_PRODUCT_PRICE).request,
    params: {
        menuId,
        prodId,
        skus
    },
    callback
})

const sagas = {
    * [apiType(GET_PRODUCT_NATURE_STATS).request]({params, callback}) {
        try {
            const response = yield getAxios('/prod/stats/nature', params)
            yield put({
                type: apiType(GET_PRODUCT_NATURE_STATS).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(GET_PRODUCT_NATURE_STATS).failure});
        }
    },
    * [apiType(GET_PRODUCT_LIST).request]({params, callback}) {
        try {
            const response = yield getAxios('/prod/prod-list', params)
            yield put({
                type: apiType(GET_PRODUCT_LIST).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(GET_PRODUCT_LIST).failure});
        }
    },
    * [apiType(CREATE_PRODUCT).request]({ params, callback }) {
        try {
            const response = yield postAxios('/prod/prod-info', params)
            yield put({
                type: apiType(CREATE_PRODUCT).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(CREATE_PRODUCT).failure});
        }
    },
    * [apiType(EDIT_PRODUCT).request]({ params, callback }) {
        try {
            const response = yield putAxios('/prod/prod-info', params)
            yield put({
                type: apiType(EDIT_PRODUCT).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(EDIT_PRODUCT).failure});
        }
    },
    * [apiType(DELETE_PRODUCT).request]({ params, callback }) {
        try {
            const response = yield deleteAxios('/prod/prod-list', params)
            yield put({
                type: apiType(DELETE_PRODUCT).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(DELETE_PRODUCT).failure});
        }
    },
    * [apiType(GET_PRODUCT_SELECTION).request]({params, callback}) {
        try {
            const response = yield getAxios('/prod/prod-list', params)
            yield put({
                type: apiType(GET_PRODUCT_SELECTION).success,
                params,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(GET_PRODUCT_SELECTION).failure});
        }
    },
    * [apiType(GET_PRODUCT_DETAIL_INFO).request]({params, callback}) {
        try {
            let response = yield getAxios('/prod/prod-info', params)
            response = {
                ...response,
                skus: response.skus.map(sku => ({
                    ...sku,
                    items: sku.items.map((item, index) => ({
                        name: response.groups[index].name,
                        item
                    }))
                }))
            }
            yield put({
                type: apiType(GET_PRODUCT_DETAIL_INFO).success,
                params,
                response,
            });
            callback && callback(response)
        } catch (e) {
            yield put({type: apiType(GET_PRODUCT_DETAIL_INFO).failure});
        }
    },
    * [apiType(GET_PRODUCT_TYPE_LIST).request]({ params }) {
        try {
            const response = yield getAxios('/prod/type', params)
            yield put({
                type: apiType(GET_PRODUCT_TYPE_LIST).success,
                response,
            });
        } catch (e) {
            yield put({type: apiType(GET_PRODUCT_TYPE_LIST).failure});
        }
    },
    * [apiType(GET_PRODUCT_TYPE_SELECTION).request]({ params, callback }) {
        try {
            const response = yield getAxios('/prod/type', params)
            yield put({
                type: apiType(GET_PRODUCT_TYPE_SELECTION).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(GET_PRODUCT_TYPE_SELECTION).failure});
        }
    },
    * [apiType(CREATE_PRODUCT_TYPE).request]({ params, callback }) {
        try {
            const response = yield postAxios('/prod/type', params)
            yield put({
                type: apiType(CREATE_PRODUCT_TYPE).success,
                response,
            });
            callback && callback(response.id)
        } catch (e) {
            yield put({type: apiType(CREATE_PRODUCT_TYPE).failure});
        }
    },
    * [apiType(EDIT_PRODUCT_TYPE).request]({ params, callback }) {
        try {
            const response = yield putAxios('/prod/type', params)
            yield put({
                type: apiType(EDIT_PRODUCT_TYPE).success,
                response,
            });
            callback && callback(response.id)
        } catch (e) {
            yield put({type: apiType(EDIT_PRODUCT_TYPE).failure});
        }
    },
    * [apiType(DELETE_PRODUCT_TYPE).request]({ params, callback }) {
        try {
            const response = yield deleteAxios('/prod/type', params)
            yield put({
                type: apiType(DELETE_PRODUCT_TYPE).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(DELETE_PRODUCT_TYPE).failure});
        }
    },
    * [apiType(GET_PRODUCT_PROPERTY_LIST).request]({ params }) {
        try {
            const response = yield getAxios('/prod/property-group', params)
            yield put({
                type: apiType(GET_PRODUCT_PROPERTY_LIST).success,
                response,
            });
        } catch (e) {
            yield put({type: apiType(GET_PRODUCT_PROPERTY_LIST).failure});
        }
    },
    * [apiType(CREATE_PRODUCT_PROPERTY).request]({ params, callback }) {
        try {
            const response = yield postAxios('/prod/property-group', params)
            yield put({
                type: apiType(CREATE_PRODUCT_PROPERTY).success,
                response,
            });
            callback && callback(response.id)
        } catch (e) {
            yield put({type: apiType(CREATE_PRODUCT_PROPERTY).failure});
        }
    },
    * [apiType(EDIT_PRODUCT_PROPERTY).request]({ params, callback }) {
        try {
            const response = yield putAxios('/prod/property-group', params)
            yield put({
                type: apiType(EDIT_PRODUCT_PROPERTY).success,
                response,
            });
            callback && callback(response.id)
        } catch (e) {
            yield put({type: apiType(EDIT_PRODUCT_PROPERTY).failure});
        }
    },
    * [apiType(DELETE_PRODUCT_PROPERTY).request]({ params, callback }) {
        try {
            const response = yield deleteAxios('/prod/property-group', params)
            yield put({
                type: apiType(DELETE_PRODUCT_PROPERTY).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(DELETE_PRODUCT_PROPERTY).failure});
        }
    },
    * [apiType(GET_PRODUCT_IMPORT_TASK_LIST).request]({ params }) {
        try {
            const response = yield getAxios('/prod/import-task/list', params)
            yield put({
                type: apiType(GET_PRODUCT_IMPORT_TASK_LIST).success,
                params,
                response,
            });
        } catch (e) {
            yield put({type: apiType(GET_PRODUCT_IMPORT_TASK_LIST).failure});
        }
    },
    * [apiType(GET_PRODUCT_IMPORT_TASK_PROGRESS).request]({ params, callback }) {
        try {
            const response = yield getAxios('/prod/import-task/progress', params)
            yield put({
                type: apiType(GET_PRODUCT_IMPORT_TASK_PROGRESS).success,
                response,
            });
            callback && callback(response.progress)
        } catch (e) {
            yield put({type: apiType(GET_PRODUCT_IMPORT_TASK_PROGRESS).failure});
        }
    },
    * [apiType(PRODUCT_IMPORT).request]({ params, callback }) {
        try {
            const response = yield postAxios('/prod/import-task/upload', params)
            yield put({
                type: apiType(PRODUCT_IMPORT).success,
                response,
            });
            callback && callback(response.id)
        } catch (e) {
            yield put({type: apiType(PRODUCT_IMPORT).failure});
        }
    },
    * [apiType(GET_SUPPLY_GROUP_LIST).request]({ params }) {
        try {
            const response = yield getAxios('/prod/menu/list', params)
            yield put({
                type: apiType(GET_SUPPLY_GROUP_LIST).success,
                response,
            });
        } catch (e) {
            yield put({type: apiType(GET_SUPPLY_GROUP_LIST).failure});
        }
    },
    * [apiType(CREATE_SUPPLY_GROUP).request]({ params, callback }) {
        try {
            const response = yield postAxios('/prod/menu/info', params)
            yield put({
                type: apiType(CREATE_SUPPLY_GROUP).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(CREATE_SUPPLY_GROUP).failure});
        }
    },
    * [apiType(EDIT_SUPPLY_GROUP).request]({ params, callback }) {
        try {
            const response = yield putAxios('/prod/menu/info', params)
            yield put({
                type: apiType(EDIT_SUPPLY_GROUP).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(EDIT_SUPPLY_GROUP).failure});
        }
    },
    * [apiType(DELETE_SUPPLY_GROUP).request]({ params, callback }) {
        try {
            const response = yield deleteAxios('/prod/menu/info', params)
            yield put({
                type: apiType(DELETE_SUPPLY_GROUP).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(DELETE_SUPPLY_GROUP).failure});
        }
    },
    * [apiType(GET_SUPPLY_GROUP_DETAIL_INFO).request]({ params, callback }) {
        try {
            const response = yield getAxios('/prod/menu/info', params)
            yield put({
                type: apiType(GET_SUPPLY_GROUP_DETAIL_INFO).success,
                response,
                params
            });
            callback && callback(response)
        } catch (e) {
            yield put({type: apiType(GET_SUPPLY_GROUP_DETAIL_INFO).failure});
        }
    },
    * [apiType(COPY_SUPPLY_GROUP).request]({ params, callback }) {
        try {
            const response = yield postAxios('/prod/menu/copy', params)
            yield put({
                type: apiType(COPY_SUPPLY_GROUP).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(COPY_SUPPLY_GROUP).failure});
        }
    },
    * [apiType(SET_SUPPLY_GROUP_RELATED_STORES).request]({ params, callback }) {
        try {
            const response = yield postAxios('/prod/menu/store', params)
            yield put({
                type: apiType(SET_SUPPLY_GROUP_RELATED_STORES).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(SET_SUPPLY_GROUP_RELATED_STORES).failure});
        }
    },
    * [apiType(GET_SUPPLY_GROUP_PRODUCT_LIST).request]({ params, callback }) {
        try {
            const response = yield getAxios('/prod/menu/prod', params)
            yield put({
                type: apiType(GET_SUPPLY_GROUP_PRODUCT_LIST).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(GET_SUPPLY_GROUP_PRODUCT_LIST).failure});
        }
    },
    * [apiType(BULK_ADD_PRODUCT_TO_SUPPLY_GROUP).request]({ params, callback }) {
        try {
            const response = yield postAxios('/prod/menu/prod', params)
            yield put({
                type: apiType(BULK_ADD_PRODUCT_TO_SUPPLY_GROUP).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(BULK_ADD_PRODUCT_TO_SUPPLY_GROUP).failure});
        }
    },
    * [apiType(BULK_DELETE_PRODUCT_FROM_SUPPLY_GROUP).request]({ params, callback }) {
        try {
            const response = yield deleteAxios('/prod/menu/prod', params)
            yield put({
                type: apiType(BULK_DELETE_PRODUCT_FROM_SUPPLY_GROUP).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(BULK_DELETE_PRODUCT_FROM_SUPPLY_GROUP).failure});
        }
    },
    * [apiType(EDIT_SUPPLY_GROUP_PRODUCT_PRICE).request]({ params, callback }) {
        try {
            const response = yield putAxios('/prod/menu/prod', params)
            yield put({
                type: apiType(EDIT_SUPPLY_GROUP_PRODUCT_PRICE).success,
                response,
            });
            callback && callback()
        } catch (e) {
            yield put({type: apiType(EDIT_SUPPLY_GROUP_PRODUCT_PRICE).failure});
        }
    },


}


export default Object.keys(sagas).map(item => {
    return function * s() {
        yield takeEvery(item, function *(args) {
            try {
                yield sagas[item](args)
            } catch (e) {
                console.log(e)
            }
        })
    }
})